<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <title>${title}</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css" media="screen">
        html, body	{ height:100%; }
        body { margin:0; padding:0; overflow:auto; text-align:left;
            background-color: ${bgcolor}; }
        object:focus { outline:none; }
        #flashContent { display:none; }
    </style>

    <!-- Enable Browser History by replacing useBrowserHistory tokens with two hyphens -->
    <!-- BEGIN Browser History required section ${useBrowserHistory}>
    <link rel="stylesheet" type="text/css" href="history/history.css" />
    <script type="text/javascript" src="history/history.js"></script>
    <!${useBrowserHistory} END Browser History required section -->
    <script type="text/javascript">
        function analytics_onready(){
            Module.SetApiUrl("http://localhost:9081/api");
        }
    </script>

    <script type="text/javascript" src="monad_analytics.js"></script>
    <script type="text/javascript">

        function f(n){
            return document.getElementById(n).value;
        }
        function testQuery(){
            var json = {i:f('i'),q:f('q')}
            var k = f('qk');
            Module.query(json,k,onData,onFail,onProgress,1);
        }
        function testAnd(){
            var keys = f('keys').split(',');
            var k = f('keySaved');
            Module.inPlaceAnd(keys,k,onData,onFail,onProgress);
        }
        function testAndTop(){
            var keys = f('keys').split(',');
            var k = f('keySaved');
            Module.inPlaceAndTop(keys,k,onData,1,onFail,onProgress);
        }
        function testAndTopWithPositionMerged(){
            var keys = f('keys').split(',');
            var k = f('keySaved');
            Module.inPlaceAndTopWithPositionMerged(keys,k,onData,1,onFail,onProgress);
        }
        function testAndNot(){
            var keys = f('keys').split(',');
            var k = f('keySaved');
            Module.andNot(keys,k,onData,onFail,onProgress);
        }
        function testOr(){
            var keys = f('keys').split(',');
            var k = f('keySaved');
            Module.inPlaceOr(keys,k,onData,onFail,onProgress);
        }
        function testTop(){
            var topk = document.getElementById("topK").value;
            Module.top(Module.IdCategory.Person,topk,100,onTop,0,onFail,onProgress);
        }
        function testGetCollectionProperties(){
            var k= document.getElementById("k9").value;
            var r = Module.getCollectionProperties(k);
            var str="";
            str+=r.count;
            onMessage(str);
        }
        function testClear(){
            var k= document.getElementById("clear").value;
            var r = Module.clearCollection(k);
            onMessage("cleared");
        }
        function onTop(obj,key){
            var str="len:"+obj.length;
            for(var i=0;i<obj.length;i++){
                str+=obj[i].id+","
            }
            onMessage(str);
        }
        function onMessage(str){
            var el = document.createElement("div");
            el.appendChild(document.createTextNode(str));
            document.getElementById("msg").appendChild(el);
        }
        function onData(obj){
            onMessage("分析结果数:"+obj.count);
        }
        function onFail(msg){
            onMessage(msg);
        }
        function onProgress(msg){
            onMessage(msg);
        }
        function testFlex(){
            alert(Module.test("hehe"));
        }
    </script>
</head>
<br>
<div id="msg" style="border:1px solid green"></div>
<div>
    <h3>api:query</h3><br/> q:<input type="text" id="q" value="test"/>,resource:<input type="text" id="i" value="test_10000"/>,save key:<input type="text" id="qk" value="1"/>
    <input type="button" onClick="javascript:testQuery();" value="query"/><br/>
</div>
<h3>merge</h3><br/>keys:<input type="text" id="keys"/> ,save key:<input type="text" id="keySaved"/>
<input type="button" onClick="javascript:testAnd();" value="And"/>
<input type="button" onClick="javascript:testAndTop();" value="AndTop"/>
<input type="button" onClick="javascript:testAndTopWithPositionMerged();" value="AndTopWithPositionMerged"/>
<input type="button" onClick="javascript:testOr();" value="Or"/>
<input type="button" onClick="javascript:testAndNot();" value="AndNot"/>
<br/>
<h3>api:top</h3><br/>top k:<input type="text" id="topK">
<input type="button" onClick="javascript:testTop();" value="top"/>
<input type="button" onClick="javascript:testFlex();" value="testFlex"/>
<br/>
<input type="text" id="k9"/>
<input type="button" onClick="javascript:testGetCollectionProperties();" value="getCollectionProperties"/>
<br/>
<input type="text" id="clear"/>
<input type="button" onClick="javascript:testClear();" value="ClearCollection"/>
<br/>
</body>
</html>
